package tjs.study.notes.eureka.clienta.user.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import tjs.study.notes.eureka.clienta.user.service.UserService;

/**
 * Created by Nicky.Tang on 2021/10/31 4:48 下午
 *
 * @since 02.12.10
 */
@RestController
@RequestMapping
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping(path = "/pay/{userId}", method = RequestMethod.GET)
    public String pay(@PathVariable("userId") String userId) {
        return userService.pay(userId);
    }

    @HystrixCommand(fallbackMethod = "newOrderHystrix")
    @RequestMapping(path = "/payFeign/{userId}/{sleepTime}", method = RequestMethod.GET)
    public String payFeign(@PathVariable("userId") String userId, @PathVariable("sleepTime") Integer sleepTime) {
        return userService.payFeign("Feign_" + userId, sleepTime);
    }

    public String newOrderHystrix(@PathVariable("userId") String userId, @PathVariable("sleepTime") Integer sleepTime) {
        return "newOrder 处于熔断状态。。。";
    }
}
